package edu.sandau.app.basic.controller;

import edu.sandau.app.basic.domain.SysUser;
import edu.sandau.app.basic.golbal.GlobalEnum;
import edu.sandau.app.basic.service.SysUserService;
import edu.sandau.app.basic.vo.BasicMsg;
import edu.sandau.app.basic.vo.BasicMsgWithData;
import edu.sandau.app.basic.vo.CreateUserRequest;
import edu.sandau.app.basic.vo.PasswordVerifyRequest;
import edu.sandau.app.basic.utils.PasswordUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/users")
@Tag(name = "用户管理", description = "用户信息管理接口")
public class SysUserController {
    
    @Autowired
    private SysUserService sysUserService;
    
    // 获取所有用户
    @GetMapping
    @Operation(summary = "获取所有用户")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "查询成功", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "查询成功",
                          "errorCode": "Ok",
                          "data": [
                            {
                              "userId": 1,
                              "username": "admin",
                              "nickname": "管理员",
                              "email": "admin@example.com",
                              "phonenumber": "13800138000",
                              "sex": "0",
                              "avatar": "",
                              "password": "******",
                              "status": "0",
                              "createTime": "2025-10-08T14:00:00",
                              "updateTime": "2025-10-08T14:00:00",
                              "userType": "0"
                            },
                            {
                              "userId": 2,
                              "username": "testuser",
                              "nickname": "测试用户",
                              "email": "test@example.com",
                              "phonenumber": "13900139000",
                              "sex": "1",
                              "avatar": "",
                              "password": "******",
                              "status": "0",
                              "createTime": "2025-10-08T14:30:00",
                              "updateTime": "2025-10-08T14:30:00",
                              "userType": "1"
                            }
                          ]
                        }"""),
                    @ExampleObject(name = "暂无用户", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "查询成功",
                          "errorCode": "Ok",
                          "data": []
                        }"""),
                    @ExampleObject(name = "查询失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "查询失败: 数据库连接异常",
                          "errorCode": "USER_QUERY_FAIL",
                          "data": null
                        }""")
                }))
    })
    public BasicMsgWithData<List<SysUser>> getAllUsers() {
        BasicMsgWithData<List<SysUser>> msg = new BasicMsgWithData<>();
        try {
            List<SysUser> users = sysUserService.getAllUsers();
            msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
            msg.setErrorMsg("查询成功");
            msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
            msg.setData(users);
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
            msg.setErrorMsg("查询失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 根据ID获取用户
    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取用户", description = "根据用户ID查询用户详细信息")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "成功查询用户", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "查询成功",
                          "errorCode": "Ok",
                          "data": {
                            "userId": 1,
                            "username": "testuser",
                            "nickname": "测试用户",
                            "email": "test@example.com",
                            "phonenumber": "13800138000",
                            "sex": "0",
                            "avatar": "http://example.com/avatar.jpg",
                            "password": "******",
                            "status": "0",
                            "createTime": "2025-10-08T14:00:00",
                            "updateTime": "2025-10-08T14:00:00",
                            "userType": "1"
                          }
                        }"""),
                    @ExampleObject(name = "用户不存在", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户不存在",
                          "errorCode": "USER_NOT_FOUND",
                          "data": null
                        }"""),
                    @ExampleObject(name = "查询失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "查询失败: 数据库连接异常",
                          "errorCode": "USER_QUERY_FAIL",
                          "data": null
                        }""")
                }))
    })
    public BasicMsgWithData<SysUser> getUserById(@PathVariable Long id) {
        BasicMsgWithData<SysUser> msg = new BasicMsgWithData<>();
        try {
            SysUser user = sysUserService.getUserById(id);
            if (user != null) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("查询成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
                msg.setData(user);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_NOT_FOUND);
                msg.setErrorMsg("用户不存在");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
            msg.setErrorMsg("查询失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 创建用户
    @PostMapping
    @Operation(summary = "创建用户", description = "创建新的系统用户")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作完成",
            content = @Content(mediaType = "application/json",
                examples = {
                    @ExampleObject(name = "创建成功", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "用户创建成功",
                          "errorCode": "Ok"
                        }"""),
                    @ExampleObject(name = "用户名不能为空", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户名不能为空",
                          "errorCode": "USER_ADD_FAIL"
                        }"""),
                    @ExampleObject(name = "密码不能为空", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "密码不能为空",
                          "errorCode": "USER_ADD_FAIL"
                        }"""),
                    @ExampleObject(name = "创建失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户创建失败: 用户名已存在",
                          "errorCode": "USER_ADD_FAIL"
                        }""")
                }))
    })
    public BasicMsg addUser(@RequestBody CreateUserRequest request) {
        BasicMsg msg = new BasicMsg();
        try {
            // 验证必需字段
            if (request.getUsername() == null || request.getUsername().trim().isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_ADD_FAIL);
                msg.setErrorMsg("用户名不能为空");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            if (request.getPassword() == null || request.getPassword().trim().isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_ADD_FAIL);
                msg.setErrorMsg("密码不能为空");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            
            // 验证枚举字段，收集所有错误
            StringBuilder validationErrors = new StringBuilder();
            
            if (request.getSex() != null && !request.getSex().trim().isEmpty()) {
                if (!"0".equals(request.getSex()) && !"1".equals(request.getSex()) && !"2".equals(request.getSex())) {
                    validationErrors.append("性别字段值无效，只能是：0=男, 1=女, 2=未知; ");
                }
            }
            
            if (request.getStatus() != null && !request.getStatus().trim().isEmpty()) {
                if (!"0".equals(request.getStatus()) && !"1".equals(request.getStatus())) {
                    validationErrors.append("用户状态字段值无效，只能是：0=正常, 1=停用; ");
                }
            }
            
            if (request.getUserType() != null && !request.getUserType().trim().isEmpty()) {
                if (!"0".equals(request.getUserType()) && !"1".equals(request.getUserType())) {
                    validationErrors.append("用户类型字段值无效，只能是：0=管理员, 1=普通用户; ");
                }
            }
            
            // 如果有验证错误，返回所有错误
            if (validationErrors.length() > 0) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_ADD_FAIL);
                msg.setErrorMsg(validationErrors.toString().trim());
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            
            // 创建 SysUser 对象
            SysUser user = new SysUser();
            user.setUsername(request.getUsername());
            user.setNickname(request.getNickname());
            user.setEmail(request.getEmail());
            user.setPhonenumber(request.getPhonenumber());
            user.setSex(request.getSex());
            user.setAvatar(request.getAvatar());
            // 对密码进行加密
            user.setPassword(PasswordUtils.encodePassword(request.getPassword()));
            user.setStatus(request.getStatus());
            user.setUserType(request.getUserType());
            
            
            int result = sysUserService.addUser(user);
            if (result > 0) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("用户创建成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_ADD_FAIL);
                msg.setErrorMsg("用户创建失败");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_ADD_FAIL);
            msg.setErrorMsg("用户创建失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 更新用户
    @PutMapping("/{id}")
    @Operation(summary = "更新用户")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "更新成功", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "用户更新成功",
                          "errorCode": "Ok"
                        }"""),
                    @ExampleObject(name = "用户名不能为空", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户名不能为空",
                          "errorCode": "USER_MODIFY_FAIL"
                        }"""),
                    @ExampleObject(name = "密码不能为空", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "密码不能为空",
                          "errorCode": "USER_MODIFY_FAIL"
                        }"""),
                    @ExampleObject(name = "更新失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户更新失败",
                          "errorCode": "USER_MODIFY_FAIL"
                        }""")
                }))
    })
    public BasicMsg updateUser(@PathVariable Long id, @RequestBody SysUser user) {
        BasicMsg msg = new BasicMsg();
        try {
            // 验证必需字段
            if (user.getUsername() == null || user.getUsername().trim().isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_MODIFY_FAIL);
                msg.setErrorMsg("用户名不能为空");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            if (user.getPassword() == null || user.getPassword().trim().isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_MODIFY_FAIL);
                msg.setErrorMsg("密码不能为空");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            
            // 对密码进行加密
            user.setPassword(PasswordUtils.encodePassword(user.getPassword()));
            
            // 验证枚举字段，收集所有错误
            StringBuilder validationErrors = new StringBuilder();
            
            if (user.getSex() != null && !user.getSex().trim().isEmpty()) {
                if (!"0".equals(user.getSex()) && !"1".equals(user.getSex()) && !"2".equals(user.getSex())) {
                    validationErrors.append("性别字段值无效，只能是：0=男, 1=女, 2=未知; ");
                }
            }
            
            if (user.getStatus() != null && !user.getStatus().trim().isEmpty()) {
                if (!"0".equals(user.getStatus()) && !"1".equals(user.getStatus())) {
                    validationErrors.append("用户状态字段值无效，只能是：0=正常, 1=停用; ");
                }
            }
            
            if (user.getUserType() != null && !user.getUserType().trim().isEmpty()) {
                if (!"0".equals(user.getUserType()) && !"1".equals(user.getUserType())) {
                    validationErrors.append("用户类型字段值无效，只能是：0=管理员, 1=普通用户; ");
                }
            }
            
            // 如果有验证错误，返回所有错误
            if (validationErrors.length() > 0) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_MODIFY_FAIL);
                msg.setErrorMsg(validationErrors.toString().trim());
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            
            // 设置要更新的用户ID，系统时间字段由服务层处理
            user.setUserId(id);
            user.setCreateTime(null); // 创建时间不允许更新
            user.setUpdateTime(null); // 更新时间由服务层自动设置
            
            int result = sysUserService.updateUser(user);
            if (result > 0) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("用户更新成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_MODIFY_FAIL);
                msg.setErrorMsg("用户更新失败");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_MODIFY_FAIL);
            msg.setErrorMsg("用户更新失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 删除用户
    @DeleteMapping("/{id}")
    @Operation(summary = "删除用户")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "删除成功", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "用户删除成功",
                          "errorCode": "Ok"
                        }"""),
                    @ExampleObject(name = "用户不存在", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户删除失败",
                          "errorCode": "USER_DELETE_FAIL"
                        }"""),
                    @ExampleObject(name = "删除失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户删除失败: 数据库连接异常",
                          "errorCode": "USER_DELETE_FAIL"
                        }""")
                }))
    })
    public BasicMsg deleteUser(@PathVariable Long id) {
        BasicMsg msg = new BasicMsg();
        try {
            int result = sysUserService.deleteUser(id);
            if (result > 0) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("用户删除成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_DELETE_FAIL);
                msg.setErrorMsg("用户删除失败");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_DELETE_FAIL);
            msg.setErrorMsg("用户删除失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 根据用户名查询
    @GetMapping("/username/{username}")
    @Operation(summary = "根据用户名查询用户")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "查询成功", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "查询成功",
                          "errorCode": "Ok",
                          "data": [
                            {
                              "userId": 1,
                              "username": "admin",
                              "nickname": "管理员",
                              "email": "admin@example.com",
                              "phonenumber": "13800138000",
                              "sex": "0",
                              "avatar": "",
                              "password": "******",
                              "status": "0",
                              "createTime": "2025-10-08T14:00:00",
                              "updateTime": "2025-10-08T14:00:00",
                              "userType": "0"
                            }
                          ]
                        }"""),
                    @ExampleObject(name = "未找到匹配的用户", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "未找到匹配的用户",
                          "errorCode": "USER_NOT_FOUND",
                          "data": null
                        }"""),
                    @ExampleObject(name = "查询失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "查询失败: 数据库连接异常",
                          "errorCode": "USER_QUERY_FAIL",
                          "data": null
                        }""")
                }))
    })
    public BasicMsgWithData<List<SysUser>> getUsersByUsername(@PathVariable String username) {
        BasicMsgWithData<List<SysUser>> msg = new BasicMsgWithData<>();
        try {
            List<SysUser> users = sysUserService.getUsersByUsername(username);
            if (users != null && !users.isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("查询成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
                msg.setData(users);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_NOT_FOUND);
                msg.setErrorMsg("未找到匹配的用户");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                msg.setData(null);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
            msg.setErrorMsg("查询失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 根据用户类型查询
    @GetMapping("/type/{userType}")
    @Operation(summary = "根据用户类型查询用户")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "查询成功", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "查询成功",
                          "errorCode": "Ok",
                          "data": [
                            {
                              "userId": 1,
                              "username": "admin",
                              "nickname": "管理员",
                              "email": "admin@example.com",
                              "phonenumber": "13800138000",
                              "sex": "0",
                              "avatar": "",
                              "password": "******",
                              "status": "0",
                              "createTime": "2025-10-08T14:00:00",
                              "updateTime": "2025-10-08T14:00:00",
                              "userType": "0"
                            }
                          ]
                        }"""),
                    @ExampleObject(name = "未找到该类型的用户", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "未找到该类型的用户",
                          "errorCode": "USER_NOT_FOUND",
                          "data": null
                        }"""),
                    @ExampleObject(name = "查询失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "查询失败: 数据库连接异常",
                          "errorCode": "USER_QUERY_FAIL",
                          "data": null
                        }""")
                }))
    })
    public BasicMsgWithData<List<SysUser>> getUsersByType(@PathVariable String userType) {
        BasicMsgWithData<List<SysUser>> msg = new BasicMsgWithData<>();
        try {
            List<SysUser> users = sysUserService.getUsersByType(userType);
            if (users != null && !users.isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("查询成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
                msg.setData(users);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_NOT_FOUND);
                msg.setErrorMsg("未找到该类型的用户");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                msg.setData(null);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
            msg.setErrorMsg("查询失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
    
    // 验证用户密码
    @PostMapping("/verify-password")
    @Operation(summary = "验证用户密码", description = "验证用户名和密码是否匹配")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "操作成功",
            content = @Content(mediaType = "application/json", 
                examples = {
                    @ExampleObject(name = "密码正确", value = """
                        {
                          "operateResult": "SUCC",
                          "errorMsg": "密码验证成功",
                          "errorCode": "Ok"
                        }"""),
                    @ExampleObject(name = "密码错误", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户名或密码错误",
                          "errorCode": "PASSWORD_ERROR"
                        }"""),
                    @ExampleObject(name = "用户不存在", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "用户不存在",
                          "errorCode": "USER_NOT_FOUND"
                        }"""),
                    @ExampleObject(name = "验证失败", value = """
                        {
                          "operateResult": "UNSUSS",
                          "errorMsg": "密码验证失败",
                          "errorCode": "VERIFY_ERROR"
                        }""")
                }))
    })
            public BasicMsg verifyPassword(@RequestBody @Schema(description = "密码验证请求", type = "object") PasswordVerifyRequest request) {
        BasicMsg msg = new BasicMsg();
        try {
            // 验证必需字段
            if (request.getUsername() == null || request.getUsername().trim().isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
                msg.setErrorMsg("用户名不能为空");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            if (request.getPassword() == null || request.getPassword().trim().isEmpty()) {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
                msg.setErrorMsg("密码不能为空");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
                return msg;
            }
            
            // 验证密码
            boolean isValid = sysUserService.verifyPassword(request.getUsername(), request.getPassword());
            
            if (isValid) {
                msg.setErrorCode(GlobalEnum.ErrorCode.Ok);
                msg.setErrorMsg("密码验证成功");
                msg.setOperateResult(GlobalEnum.OperateResult.SUCC);
            } else {
                msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
                msg.setErrorMsg("用户名或密码错误");
                msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
            }
        } catch (Exception e) {
            msg.setErrorCode(GlobalEnum.ErrorCode.USER_QUERY_FAIL);
            msg.setErrorMsg("密码验证失败: " + e.getMessage());
            msg.setOperateResult(GlobalEnum.OperateResult.UNSUSS);
        }
        return msg;
    }
}
